package qldc.pm.tienan.service.impl;

import java.util.Date;
import java.util.List;

import qldc.pm.tienan.NoSuchTEMP_PhieuThongTinVeNguoiCoTienAnException;
import qldc.pm.tienan.model.PhieuThongTinVeNguoiCoTienAn;
import qldc.pm.tienan.model.TEMP_PhieuThongTinVeNguoiCoTienAn;
import qldc.pm.tienan.model.TEMP_TienAn;
import qldc.pm.tienan.model.impl.TEMP_PhieuThongTinVeNguoiCoTienAnImpl;
import qldc.pm.tienan.service.TEMP_PhieuThongTinVeNguoiCoTienAnLocalServiceUtil;
import qldc.pm.tienan.service.base.TEMP_PhieuThongTinVeNguoiCoTienAnLocalServiceBaseImpl;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.Validator;

/**
 * The implementation of the t e m p_ phieu thong tin ve nguoi co tien an local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link qldc.pm.tienan.service.TEMP_PhieuThongTinVeNguoiCoTienAnLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see qldc.pm.tienan.service.base.TEMP_PhieuThongTinVeNguoiCoTienAnLocalServiceBaseImpl
 * @see qldc.pm.tienan.service.TEMP_PhieuThongTinVeNguoiCoTienAnLocalServiceUtil
 */
public class TEMP_PhieuThongTinVeNguoiCoTienAnLocalServiceImpl
    extends TEMP_PhieuThongTinVeNguoiCoTienAnLocalServiceBaseImpl {
	public TEMP_PhieuThongTinVeNguoiCoTienAn addTEMPPhieu(long tienAnId, long userId, String userName,
			String maSoHoSoTienAnTuToaAn, String nguoiTrichLuc,
			String thamPhan,
			String soDinhDanhCaNhan, String chuThich, 
			String noiTamTruDiaChi,
			String hoTenVoHoacChong,
			String hoTenCha,
			String hoTenMe, String noiThuongTruDiaChi)
			throws SystemException {
		long PhieuThongTinVeNguoiCoTienAnId = counterLocalService.increment(TEMP_PhieuThongTinVeNguoiCoTienAn.class.getName());
		TEMP_PhieuThongTinVeNguoiCoTienAn phieuThongTin = createTEMP_PhieuThongTinVeNguoiCoTienAn(PhieuThongTinVeNguoiCoTienAnId);
		
		phieuThongTin.setUserId(userId);
		phieuThongTin.setUserName(userName);
		phieuThongTin.setCreateDate(new Date());
		phieuThongTin.setNoiTamTruDiaChi(noiTamTruDiaChi);
		phieuThongTin.setHoTenCha(hoTenCha);
		phieuThongTin.setHoTenMe(hoTenMe);
		phieuThongTin.setHoTenVoHoacChong(hoTenVoHoacChong);
		phieuThongTin.setTienAnId(tienAnId);
		phieuThongTin.setMaSoHoSoTienAnTuToaAn(maSoHoSoTienAnTuToaAn);
		phieuThongTin.setNguoiTrichLuc(nguoiTrichLuc);
		phieuThongTin.setThamPhan(thamPhan);
		phieuThongTin.setSoDinhDanhCaNhan(soDinhDanhCaNhan);
		phieuThongTin.setChuThich(chuThich);
		phieuThongTin.setNoiThuongTruDiaChi(noiThuongTruDiaChi);

		phieuThongTin = addTEMP_PhieuThongTinVeNguoiCoTienAn(phieuThongTin);

		return phieuThongTin;
	}
	public TEMP_PhieuThongTinVeNguoiCoTienAn findByTienAnId(long tienAnId) {
		TEMP_PhieuThongTinVeNguoiCoTienAn phieuThongTinVeNguoiCoTienAn = null;

		try {
			phieuThongTinVeNguoiCoTienAn = temp_PhieuThongTinVeNguoiCoTienAnPersistence.findByTienAnId(tienAnId);
		} 
		catch (SystemException e) {
		}
		catch (NoSuchTEMP_PhieuThongTinVeNguoiCoTienAnException e) {
			
		}

		return phieuThongTinVeNguoiCoTienAn;
	}
	public void xoaByTienAnId(long tienAnId) {
		TEMP_PhieuThongTinVeNguoiCoTienAn phieuThongTinVeNguoiCoTienAn = findByTienAnId(tienAnId);
		if (Validator.isNotNull(phieuThongTinVeNguoiCoTienAn))
			try {
				TEMP_PhieuThongTinVeNguoiCoTienAnLocalServiceUtil.deleteTEMP_PhieuThongTinVeNguoiCoTienAn(phieuThongTinVeNguoiCoTienAn);
			} catch (SystemException e) {
				System.out.println("Not found");
			}

	}
	public void xoaAllTempPhieuByDoiTuongTienAnId(long doiTuongTienAnId){
		List<TEMP_TienAn> tienAn;
		try {
			tienAn = temp_TienAnPersistence.findByDoiTuongTienAnId(doiTuongTienAnId);
			for (TEMP_TienAn ts : tienAn){
				xoaByTienAnId(ts.getTienAnId());
			}
		} catch (SystemException e) {
			System.out.println("Not found data");
		}
		
	}
}
